package bookstore.common;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

@WebListener()
public class UserEnterListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        Integer totalcount = (Integer) se.getSession().getServletContext().getAttribute("totalcount");
        Integer accesscount = (Integer) se.getSession().getServletContext().getAttribute("accesscount");
        se.getSession().getServletContext().setAttribute("totalcount", totalcount + 1);
        se.getSession().getServletContext().setAttribute("accesscount", accesscount + 1);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        Integer accesscount = (Integer) se.getSession().getServletContext().getAttribute("accesscount");
        se.getSession().getServletContext().setAttribute("accesscount", accesscount - 1);
    }
}
